package com.liusuai.yixian.login;

/*mapper接口*/

//1 @Mapper将UserDao声明为一个Mapper接口
//2 @Results是结果映射列表，@Result中property是User类的属性名，colomn是数据库表的字段名
//3 @Select, @Insert 分别代表了执行的真实SQL

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface UserMapper {

    @Select("select * from user where name=#{name} and pwd=#{pwd}")
    List<UserBean> login(@Param("name") String name, @Param("pwd") String pwd);

    @Select("select * from user where name=#{name}")
    List<UserBean> selectUser(@Param("name") String name);

    @Select("select * from user")
    List<UserBean> selectAllUsers();

    @Select("select * from user where id=#{id}")
    UserBean selectUserById(@Param("id") String id);

    @Insert("insert into user(name,phone,pwd) value(#{name},#{phone},#{pwd})")
    int insert(UserBean userBean);

    @Update("UPDATE user SET loginId = #{loginId} WHERE  id =#{id}")
    int updateLoginId(UserBean userBean);

    @Update("UPDATE user SET socketId = #{socketId} WHERE id =#{id}")
    int updateSocketId(@Param("socketId") String socketId,@Param("id") String userId);

    @Select("select * from user where id=#{id}")
    UserBean selectUserByID(@Param("id") String id);

}